﻿package test {
	import extremefx.unitTest.Trace;
	import extremefx.events.EventArgs;
	import extremefx.events.ObjectEventArgs;
	import extremefx.events.ProgressEventArgs;
	import extremefx.modules.SoundPlayer;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;	

	/**
	 * @author Marcelo Volmaro
	 */
	 
	[Frame(factoryClass="extremefx.Preloader")];
	public class SoundPlayerTest extends Sprite {
		private var _tf:TextField;
		private var _sp:SoundPlayer;
		
		public function main():void{
			var tf:TextField = _tf = new TextField();
			var tfmt:TextFormat = new TextFormat("arial unicode ms", 14, 0);
			stage.addEventListener(Event.RESIZE, resizeStage);
			addChild(tf);
			tf.x = 0;
			tf.y = 0;
			tf.width = stage.stageWidth;
			tf.height = stage.stageHeight;
			tf.defaultTextFormat = tfmt;
			
			_sp = new SoundPlayer();
			_sp.setUrl("sound.mp3");
			
			_sp.onComplete.add(onComplete);
			_sp.onMetaData.add(onMetadata);
			_sp.onOpen.add(onOpen);
			_sp.onPlayComplete.add(onPlayComplete);
			_sp.onProgress.add(onProgress);
			
			_sp.play();
		}
		
		private function onProgress(pSender:SoundPlayer, pArgs:ProgressEventArgs):void {
			_tf.appendText("on Progress:"+pArgs.percent);
			_tf.appendText("\n");
		}

		private function onPlayComplete(pSender:SoundPlayer, pArgs:EventArgs):void {
			_tf.appendText("onPlayComplete\n");
		}
		
		private function onOpen(pSender:SoundPlayer, pArgs:EventArgs):void {
			_tf.appendText("onOpen\n");
		}

		private function onMetadata(pSender:SoundPlayer, pArgs:ObjectEventArgs):void {
			_tf.appendText("onMetadata\n");
			_tf.appendText(Trace.obj(pArgs.value));
		}

		private function onComplete(pSender:SoundPlayer, pArgs:EventArgs):void {
			_tf.appendText("onComplete\n");
		}

		private function resizeStage(event:Event):void {
			_tf.width = stage.stageWidth;
			_tf.height = stage.stageHeight;
		}
	}
}
